// This program places each word in a text file on a seperate line.
#include <fstream>
#include <iostream>

using namespace std;

const int MAX = 5000;

int lineCount = 0;

string outFilename;
string inFilename;

ifstream inFile;
ofstream outFile;

string data[MAX];
int main() {
	cout << "Places each word on a seperate line.\n";
	cout << "Input file: ";
	cin >> inFilename;
	cin.ignore();

	cout << "Output File: ";
	cin >> outFilename;
	cin.ignore();

	inFile.open(inFilename.c_str());
	if(inFile.is_open()) {
		cout << "Processing...\n";

		outFile.open(outFilename.c_str());
		while (!inFile.eof()) {
			for (int x = 0; x < MAX; x++) {
				inFile >> data[x];
				if(data[x] != "") {
					outFile << data[x] << endl;
					lineCount++;
				}
			}
		}
		inFile.close();
		outFile.close();
	}

	else {
		cout << "Invalid input file.";
		cin.get();
		exit(1);
	}

	cout << "Finished.\n";
	cout << "Seperated into " << lineCount << " lines";
	cin.get();
}
